package com.scy.java.loop;
//存钱问题
public class save {
    public static void main(String[] args) {

        fristProblem();
        twoProblem();
        snailProblem();
    }
    //第几天会超过10元
    public static void fristProblem() {
        int day = 1;
        for (double money = 1.0; money < 10.0;) {

            money*=1.5;
            day++;
            System.out.println("第"+day+"天存了"+money+"钱");
        }
        System.out.println("第"+day+"天会超10元");

    }
//    一个月后会存多少钱
    public static void twoProblem(){
        double money = 1.0;
        double sum = 0.0;
        for (int day = 2; day < 30; day++) {
            sum+=money;
            money*=1.5;
            System.out.println("第"+day+"天存了"+money+"钱");

        }
        System.out.println("一个月后会存"+sum+"钱");
    }
//    蜗牛白天三米，晚上掉两米，10米井多久出去
    public static void snailProblem(){
        int day = 1;
        double sum = 0;//爬过的距离
        while (true){
            //白天三米
            sum+=3;
            System.out.println("第"+day+"天爬了"+sum+"米");
            if (sum>=10)break;
            //晚上掉2米
            sum-=2;
            System.out.println("第"+day+"天晚上掉了"+sum+"米");
            day++;
        }
        System.out.println("蜗牛需要"+day+"天才能爬出井");

    }
}
